import { Card, message } from "antd"
import login from '../../store/modules/user'
import styles from '../Login/index.scss'
import { Button, Checkbox, Form, Input } from 'antd';
import { useDispatch } from "react-redux";
import { useNavigate } from "react-router-dom";





const Login = () => {

  const dispatch = useDispatch()
  const navigaet = useNavigate()
    const onFinish = async (values) => {
      await dispatch(login(values))
      navigaet("/")
      message.success('登录成功')
};

const onFinishFailed = (errorInfo) => {
  console.log('Failed:', errorInfo);
};
    return (<div className={styles.login}>
        <Card title="极客项目登录" extra={<a href="#">More</a>} style={{ width: 300 }}>
      <Form
    name="basic"
    labelCol={{ span: 8 }}
    wrapperCol={{ span: 16 }}
    style={{ maxWidth: 600 }}
    initialValues={{ remember: true }}
    onFinish={onFinish}
    onFinishFailed={onFinishFailed}
    autoComplete="off"
  >
    <Form.Item
      label="用户名"
      name="username"
      rules={[{ required: true, message: '请输入用户名' }]}
    >
      <Input />
    </Form.Item>

    <Form.Item
      label="密码"
      name="password"
      rules={[{ required: true, message: '请输入密码' }]}
    >
      <Input.Password />
    </Form.Item>

    <Form.Item name="remember" valuePropName="checked" label={null}>
      <Checkbox>记住我</Checkbox>
    </Form.Item>

    <Form.Item label={null}>
      <Button type="primary" htmlType="submit">
        登录
      </Button>
    </Form.Item>
  </Form>
    </Card>
    </div>)
}
export default Login